package com.wjc.lib

import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.createCoroutine

/**
 * ClassName: com.wjc.lib
 * Description:
 * JcChen on 2022.07.25.15:24
 */
class Test {
    val test = suspend {
        println("suspend")
        5
    }.createCoroutine(object : Continuation<Int> {  //
        override val context: CoroutineContext
            get() = EmptyCoroutineContext

        override fun resumeWith(result: Result<Int>) {
            println("result = $result")
        }

    })

//    public fun <T> (suspend () -> T).createCoroutine(completion: Continuation<T): Continuation<Unit>

}


class test2 {
    fun main() {
        "".buildString2 { sb: StringBuilder ->
            sb.append("a")
            sb.append("b")
            sb.append("c")
        }
    }

    // block T.()->R
    private fun String.buildString(block: StringBuilder.() -> Unit): String {
        val sb = StringBuilder()
        sb.block()
        return sb.toString()
    }

    // block ()-> Unit
    private fun String.buildString2(block: (builder: StringBuilder) -> Unit): String {
        val sb = StringBuilder()
        block(sb)
        return sb.toString()
    }
}